<template>
	<view>
		<u-navbar title="积分排行" autoBack placeholder :border="false"></u-navbar>
		<u--image src="/static/image/home/bgc2.jpg"
			width="100vw" height="220px"></u--image>
		<view style="padding: 32rpx;background-color: #fff;">
			<u-empty
					v-if="!loading && list.length===0"
					text="暂无排行"
			        mode="data"
			        icon="http://cdn.uviewui.com/uview/empty/data.png"
			>
			</u-empty>
			<view :style="{marginBottom: list.length-1 === index ? 0 : '32rpx'}" class="rank-item" v-for="(item, index) in list" :key="index">
				<view style="width: 24px;text-align: center;" v-if="index>2">{{index+1 > 9 ? index+1 : '0' + (index+1)}}</view>
				<u--image v-else :src="imgs[index]"
					width="24" height="24" mode="widthFix"></u--image>
				
				<view class="rank-item-r">
					<view class="rank-item-r-1">
						<u--image :src="item.avatar"
							width="40" height="40" shape="circle"></u--image>
						<text style="padding-left: 16rpx;">{{item.realname}}</text>
					</view>
					<text :class="[ index > 2 ? 'rank-points1' : 'rank-points' ]">{{item.totalPoints}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {rank} from '@/api/home.js';
	export default {
		data() {
			return {
				imgs: [
					'/static/image/home/5.png',
					'/static/image/home/6.png',
					'/static/image/home/7.png',
				],
				list: [],
				loading: true
			}
		},
		onLoad() {
			this.loading = true;
			this.$cuLoading('加载中...').then(() => {
				rank().then(res => {
					this.list = res.result;
				}).finally(() => {
					this.loading = false;
					uni.hideLoading();
				})
			})
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
</style>

<style lang="scss" scoped>
	.rank-item {
		display: flex;
		align-items: center;
		.rank-item-r {
			padding-left: 30rpx;
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.rank-item-r-1 {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			.rank-points {
				color: #ff9d4f; 
			}
			.rank-points1 {
				color: #000; 
			}
		}
	}
</style>
